// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

TestCase := Window {
    width: 100phx;
    height: 100phx;
    ti := FocusScope {
        key-pressed(event) => {
            shift_modifier = event.modifiers.shift;
            alt_modifier = event.modifiers.alt;
            control_modifier = event.modifiers.control;
            meta_modifier = event.modifiers.meta;
            accept;
        }
        key-released(event) => {
            shift_modifier = event.modifiers.shift;
            alt_modifier = event.modifiers.alt;
            control_modifier = event.modifiers.control;
            meta_modifier = event.modifiers.meta;
            accept;
        }
    }

    property <bool> input_focused: ti.has_focus;
    property <bool> shift_modifier;
    property <bool> alt_modifier;
    property <bool> control_modifier;
    property <bool> meta_modifier;
}

/*
```rust
use slint::platform::Key;

let instance = TestCase::new().unwrap();
slint_testing::send_mouse_click(&instance, 5., 5.);
assert!(instance.get_input_focused());

slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), true);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), true);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Shift.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), true);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Alt.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), true);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::AltGr.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), true);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

// AltGr does not set the alt modifier
slint_testing::send_keyboard_char(&instance, Key::Alt.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::AltGr.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Control.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), true);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::ControlR.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), true);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Control.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), true);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::ControlR.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, Key::Meta.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), true);

slint_testing::send_keyboard_char(&instance, Key::MetaR.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), true);

slint_testing::send_keyboard_char(&instance, Key::Meta.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), true);

slint_testing::send_keyboard_char(&instance, Key::MetaR.into(), false);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);

// Check that loss of windows focus and regaining it, resets the internal modifier
// state.
slint_testing::send_keyboard_char(&instance, Key::Control.into(), true);
slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), true);
assert_eq!(instance.get_meta_modifier(), false);

// Pretend that Ctrl-something results in a loss of focus, so we never receive the "something" key,
// but we observe a loss of focus.
// TODO: create public API for window focus gain/loss
let window_inner = slint::private_unstable_api::re_exports::WindowInner::from_pub(instance.window());
window_inner.set_active(false);
window_inner.set_focus(false);
window_inner.set_active(true);
window_inner.set_focus(true);

slint_testing::send_keyboard_char(&instance, 'a', true);
slint_testing::send_keyboard_char(&instance, 'a', false);
assert_eq!(instance.get_shift_modifier(), false);
assert_eq!(instance.get_alt_modifier(), false);
assert_eq!(instance.get_control_modifier(), false);
assert_eq!(instance.get_meta_modifier(), false);
```
*/
